<style scoped src="./index.scss" lang="scss" rel="stylesheet/scss"></style>
<template src="./index.html"></template>
<script>
export default {
  mixins: [Vue.prototype.$vFN.Mixins.Base, Vue.prototype.$vFN.Mixins.Edit],
  components: {},
  data() {
    return {
      appWindow: window,
      form: {
        // 1：商品折扣价 or 2：实际支付
        settle_module: 1,
        // 结算周期（天）
        // settle_cycle: 1,
        // 订单分润条件
        estimate_module: 1,
        // 提现审核
        withdraw_audit: 1,

        // 多少等级以上可以自动通过：自动审核策略：等级ID
        level_id: null,
        // 低于多少金额可以通过：自动审核策略：金额
        threshold_amount: null,
      },

      load: true,
    };
  },
  methods: {
    // 验证 
    validate() {
      return new Promise((resolve, reject) => {
        this.$refs["editForm"].validate((valid) => {
            valid ? resolve(true) : resolve(false)
        });
      });
    },
    async sum() {
      if (!await this.validate()) {
        return
      }
      this.load = true;
      let res = await this.$vFN.Http.post({
        url: "plugin/team-dividend/admin/setting/setSettle",
        data: this.form,
      }, window);
      if(res.code == 200) {
        this.$vFN.Tools.messageSuccess("操作成功")
        this.getData();
      }
    },

    async getData() {
      let res = await this.$vFN.Http.post({
        url: "plugin/team-dividend/admin/setting/getBase",
      }, window);
      if(res.data.settle_set != null) {
        this.form = res.data.settle_set;
        this.form.settle_module = JSON.parse(res.data.settle_set.settle_module);
        // this.form.settle_cycle = JSON.parse(res.data.settle_set.settle_cycle);
        this.form.estimate_module = JSON.parse(res.data.settle_set.estimate_module);
        this.form.withdraw_audit = JSON.parse(res.data.settle_set.withdraw_audit);
        this.form.level_id = JSON.parse(res.data.settle_set.level_id);
        this.form.threshold_amount = JSON.parse(res.data.settle_set.threshold_amount);
      }
      this.load = false;
      
    },
    
    // 初始化
    async init() {
      this.getData();
    },
  },
  mounted() {
    this.init();
  },
  activated() {},
};
</script>